#ifndef _CODER_H
#define _CODER_H

#include <string>
#include <utility>

#include <openssl/evp.h>

typedef std::pair<unsigned char*, unsigned> cpair;

class Coder {
  public:
    // seed - seed of random.
    Coder(const std::string& key, int seed, int nrounds = 5);
    inline ~Coder() {
      if (_salt)
        delete _salt;
    };

    cpair AESEncrypt(const std::string& raw_string);
    std::string AESDecrypt(cpair cipher_string);
    void UpdateKey(const std::string& key);

  private:
    int _AESInit();

    std::string _key;
    unsigned _nrounds;
    char* _salt;
    EVP_CIPHER_CTX _encr;
    EVP_CIPHER_CTX _decr;
};

#endif  // _CODER_H
